package com.gitee.magic.jdbc.persistence.source.jdbc.script.converter;

import java.util.ArrayList;
import java.util.List;

import com.gitee.magic.core.utils.StringUtils;
import com.gitee.magic.jdbc.persistence.source.jdbc.script.def.BaseColumnFieldScriptDef;

/**
 * @author start
 */
public class FieldEnum extends BaseColumnFieldScriptDef {

	private Class<?> classes;
	
	public FieldEnum(Class<?> classes) {
		this.classes=classes;
	}

	@Override
	public String buildScripts(int length, int dp) {
		super.buildScripts(length, dp);
		List<String> types=new ArrayList<>();
		for(Object e:this.classes.getEnumConstants()) {
			types.add("'"+e+"'");
		}
		return String.valueOf(getDataType())+"("+StringUtils.listToString(types)+")";
	}

	@Override
	public String getDataType() {
		return "ENUM";
	}

}
